package com.burgeon.backend.EnterpriseWeChat.controller;

import com.burgeon.backend.EnterpriseWeChat.entity.EWEmployee;
import com.burgeon.backend.EnterpriseWeChat.service.EWInfoService;
import com.burgeon.backend.EnterpriseWeChat.service.EWelcomeService;
import com.burgeon.backend.stsutil.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("ew/welcome")
@CrossOrigin
public class EWelcomeController extends EWBaseController{
    @Autowired
    private EWelcomeService eWelcomeService;
    @Autowired
    private EWInfoService ewInfoService;

    /**
     * 登录企业微信
     * @param code 是企业微信生成的code，
     * @param token 是客户用户的注册码
     * @return
     */
    @RequestMapping("getEWLogin")
    public ResponseResult<EWEmployee> getEWLogin(String code, String token, HttpSession session) {
        System.err.println(code);
        System.err.println(token);

        EWEmployee data = eWelcomeService.GetOpenId(code,token,session);
        System.err.println("登录的导购============"+data);

        return new ResponseResult<>(SUCCESS,data);
    }

    @RequestMapping("getAccessToken")
    public ResponseResult<String> getAccessToken() {
        String data = ewInfoService.getAppAccessToken("123");
        return new ResponseResult<>(SUCCESS,data);
    }

    /**
     * 生成企业微信名片
     * @param token
     * @return
     */
    @RequestMapping("createQyCard")
    public ResponseResult<String> createQyCard(String qyCard,String token,String empId) {
        System.err.println("企业微信名片*******************"+token+empId);
        String data = eWelcomeService.QyCode(qyCard, token, empId);
        return new ResponseResult<>(SUCCESS,data);
    }

    /**
     * 获取服务器地址
     * @param token
     * @return
     */
    @RequestMapping("getWeChatUrl")
    public ResponseResult<String> getWeChatUrl(String token) {
        String data = eWelcomeService.getWeChatUrl(token);
        return new ResponseResult<>(SUCCESS,data);
    }

    @RequestMapping("upCardUrl")
    public ResponseResult<String> upCardUrl(MultipartFile file, String token,String empId) {
        System.err.println("企业微信名片*******************"+token+empId);
        String data = eWelcomeService.upCardUrl(file, token, empId);
        return new ResponseResult<>(SUCCESS,data);
    }

    @RequestMapping("IsInvite")
    public ResponseResult<String> IsInvite(String id,String token) {
        String data = eWelcomeService.IsActive(id,token);
        return new ResponseResult<>(SUCCESS,data);
    }

//    @RequestMapping("getEWInfo")
//    public ResponseResult<EWEmployee> getEWLogin(String HttpSession session) {
//        System.err.println(code);
//        System.err.println(token);
//
//        EWEmployee data = eWelcomeService.GetOpenId(code,token,session);
//
//        return new ResponseResult<EWEmployee>(SUCCESS,data);
//    }


}
